package com.wanjl.springMvc.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author WanJl
 * @version 1.0
 * @title MyInterceptor02
 * @description
 * @create 2024/11/17
 */
@Component
public class MyInterceptor02 implements HandlerInterceptor {
    /**
     * 当前方法会在Controller层的方法被调用前执行。
     * @param request
     * @param response
     * @param handler
     * @return 一个布尔类型值，如果是true，则放行，如果是false则终止。
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("02....preHandle...");
        return true;
    }

    /**
     * 原始方法调用后，执行本方法
     * @param request
     * @param response
     * @param handler
     * @param modelAndView
     * @throws Exception
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("02......postHandle...");
    }

    /**
     * 原始方法调用完成后，执行本方法
     * @param request
     * @param response
     * @param handler
     * @param ex
     * @throws Exception
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("02......afterCompletion...");
    }
}
